from rest_framework import serializers
from firepark_admin.models import Userinfo, Plate, use_records, Info


class Infoserlizer(serializers.ModelSerializer):
    token = serializers.CharField(write_only=True)

    class Meta:
        model = Info
        fields = "__all__"

    def validate(self, attrs):
        print(attrs['token'], "这是token")
        s = Userinfo.objects.filter(token=attrs['token']).first()
        del attrs['token']
        attrs['name'] = s
        print(attrs)
        return attrs

    def create(self, validated_data):
        print(validated_data)
        return Info.objects.create(**validated_data)


class INofgetserlizer(serializers.ModelSerializer):
    class Meta:
        model = Info
        fields = "__all__"


class Userinfoserlizer(serializers.ModelSerializer):
    class Meta:
        model = Userinfo
        fields = "__all__"


class chepanserlizer(serializers.ModelSerializer):
    token = serializers.CharField(write_only=True)

    class Meta:
        model = Plate
        fields = "__all__"

    def validate(self, attrs):
        print(attrs['token'], '这是token值')
        print(attrs, "这是值")
        x = Userinfo.objects.filter(token=attrs['token']).first()
        attrs['users'] = x
        del attrs['token']
        return attrs


class  getchepanserlizer(serializers.ModelSerializer):
    class Meta:
        model = Plate
        fields = "__all__"


class Warehousingserlizer(serializers.ModelSerializer):
    status = serializers.CharField(source="get_status_display")
    add_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S")

    class Meta:
        model = use_records
        fields = "__all__"
